var swiper = new Swiper(".mySwiper", {
    spaceBetween: 30,
    centeredSlides: true,
    loop: true,
    autoplay: {
        delay: 2500,
        disableOnInteraction: false,
    },
    pagination: {
        el: ".swiper-pagination",
        clickable: true,
    },
    navigation: {
        nextEl: ".swiper-button-next",
        prevEl: ".swiper-button-prev",
    },
});
layui.use(["layer", "util"], function() {
    let $ = layui.$;
    let layer = layui.layer,
        util = layui.util;
    //  请求
    function qq(type, url, data) {
        return new Promise((res, rej) => {
            $.ajax({
                type: type,
                url: url,
                dataType: "JSON",
                data: data,
                success: function(ress) {
                    res(ress);
                },
                error: function(err) {
                    rej(err.status);
                },
            });
        });
    }
    // 结果
    async function aa(type, url, data) {
        try {
            let res = await qq(type, url, data);
            console.log(res);
            xr(res.data);
        } catch (e) {
            console.log(e);
        }
    }

    // 渲染
    var _li = $(".layui-tab-item ul");

    function xr(data) {
        _li.html();
        var date = "";
        for (let l of data) {
            date += `
                  <li>
                    <img src="http://safe-img.xhscdn.com/bw1/96fb0215-a340-4fb9-bb01-29f382a4a296?imageView2/2/w/1080/format/jpg" alt="">
                    <h1>${l.name}</h1>
                    <p>￥<span>${l.price}</span></p>
                    <span>185.6折</span>
                  </li>
                `;
        }
        _li.html(date);
    }

    aa("get", "https://liu.zzgoodqc.cn/teas");
    util.on("lay-on", {
        details: function() {
            console.log(123);
            layer.open({
              move: false,
              offset: "auto",
              type: 1,
              shadeClose: true,
              title: "优惠信息",
              shade: 12.0, // 不显示遮罩
              content: `
                    <h4>优惠活动</h4>
                    <p><span>折扣</span>指定商品18.5折起
                        <a href="">查看</a>
                    </p>
                    <h4>门店信息</h4>
                    <p>地址:郑州市荥阳市荥阳吾悦广场3层3036</p>
                    <p>门店电话:<a>0371-6505508</a></p>
                    <p>门店营业时间:周一至周日 10:00-21:30</p>
                    <p><a href="">产看门店服务资质</a></p>
                    <p><a href="">产看食品安全档案</a></p>
                 `,
            });
        },
        close: function() {
            $(this).parent().css("display", "none");
        },
    });
});